package com.tmeone.erpone.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TDriver;
import com.tmeone.erpone.service.ITDriverService;

import com.tmeone.erpone.service.ITVehicleService;
import com.tmeone.erpone.service.TLogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
public class TDriverController {

    @Autowired
    private TLogisticsService logisticsService;

    @Autowired
    private ITVehicleService vehicleService;

    @Autowired
    private ITDriverService driverService;



    //驾驶员分页
    @GetMapping("driver")
    public JsonResult pageDriver(@RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                                 @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        Page<TDriver> org = new Page<>(current,pageSize);
        return new JsonResult(1,driverService.getPageDriver(org));
    }

    //添加
    @PostMapping("driver")
    public JsonResult addDriver(@RequestBody TDriver driver){
        driver.setDriverId(UUID.randomUUID().toString().replace("-","").substring(0,8));
        return new JsonResult(1,driverService.save(driver));
    }

    //修改
    @PutMapping("driver")
    public JsonResult updateDriver(@RequestBody TDriver driver){
        return new JsonResult(1,driverService.updateById(driver));
    }

    //删除
    @DeleteMapping("driver/{id}")
    public JsonResult deleteDriver(@PathVariable String id){
        return new JsonResult(1,driverService.removeById(id));
    }

    //查询所有的车辆信息
    @GetMapping("vehicleAll")
    public JsonResult selectVehicle(){
        return new JsonResult(1,vehicleService.vehicleByNumberPlate());
    }

    //查询所有的公司名称
    @GetMapping("logisticsAll")
    public JsonResult selectLogistics(){
        return new JsonResult(1,logisticsService.list());
    }

    //查询驾驶员名称和驾驶证号
//    @GetMapping("/driverNameLicense/{input1}/{input2}/{curr}/{pageSize}")
    @GetMapping("/driverNameLicense")
    public JsonResult selectDriverNameLicense( String input1, String input2, Integer curr,Integer pageSize){
        Page<TDriver> org = new Page<>(1,pageSize);
        return new JsonResult(1,driverService.getPageDriverNameID(org,input1,input2));
    }
}
